(defun probl-9 (n)
    (do ((i 1 (1+ i)))
	((> i n))
      (do ((j 1 (1+ j)))
	  ((> j n))
	(do ((k 1 (1+ k)))
	    ((> k n))
	    (if (and 
		   (eq 
		    (+ i j k) 
		    1000) 
		   (eq
		    (+ (expt i 2) (expt j 2))
		    (expt k 2))) (print (* i j k)))))))
(probl-9 1000)

(defun project-euler-009 ()
  (do* ((num 1000)
        (c (floor (/ num 3)) (1+ c))
        (result))
      ((> c num) result)
    (do* ((b (floor (/ c 2)) (1+ b))
         (a (- num (+ c b)) (- num (+ c b))))
        ((>= b c))
      (when (>= a 0)
        (when (= (+ (* a a) (* b b)) (* c c))
          (setf result (cons (* a b c) result))))
      )))

(defun search-for-triple (c)
  (loop for a from 0 to (- 1000 c) do
       (let ((b (- 1000 (+ a c))))
	 (if (> a b) (return-from search-for-triple))
	 (if (= (+ (* a a) (* b b)) (* c c)) (format t "~a ~a ~a~%" a b c)))))

(loop for c from 1000 downto 0 do
     (search-for-triple c))